package hotLeetcode;

import java.util.Arrays;

public class H322Leetcode {
    public int coinChange(int[] coins, int amount) {

        int[] dp = new int[amount + 1];
        Arrays.fill(dp, amount + 1);
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            for (int coin : coins) {
                if (i >= coin) {
                    dp[i] = Math.min(dp[i], dp[i - coin] + 1);
                }
            }
            
        }
        return dp[amount] == amount + 1 ? -1 : dp[amount];

    }


    public static void main(String[] args) {
        int[] coins = {1, 2, 5};
        int amount = 11;
        H322Leetcode h322Leetcode = new H322Leetcode();
        h322Leetcode.coinChange(coins, amount);
    }
}
